home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Arsenal - The Cutting Edge of Hacking / Hacker's Arsenal - The Cutting Edge of Hacking.iso / texts / nix / unixsec.txt < prev    next >
Encoding:
Text File  |  2001-07-11  |  49.3 KB  |  956 lines

  1. Basic Local/Remote Unix Security for Unix Newbies
  2. <===============================================>
  3. version 1.0, 21/11/99
  4.  
  5. Written by: R a v e N, Black Sun Research Facility.
  6.  
  7. Black Sun Research Facility - http://blacksun.box.sk
  8.  
  9. <--! Begin copyright bullshit !-->
  10. All copyrights are reserved. You may distribute this tutorial freely, as long
  11. as you keep our names and Black Sun Research Facility's URL at the top of this
  12. tutorial.
  13. I have written this tutorial for you, the readers. But I also wish to remain
  14. the author of this guide, meaning I do not want people to change a line or two
  15. and then claim that the whole guide is theirs. If you wish to create an
  16. altered version of this tutorial, please contact me by Email -
  17. barakirs@netvision.net.il.
  18. <--! End copyright bullshit !-->
  19.  
  20. <--! Begin disclaimer !-->
  21. Yada yada yada... you know the drill. I did not write this tutorial for people
  22. to learn "how to hack" and crack into and possibly damage other machines. It
  23. is solely intended to teach the reader a lesson about Unix security.
  24. Also, I am not responsible to any damage caused by using any of the techniques
  25. explained in this guide.
  26. <--! End disclaimer !-->
  27.  
  28.  
  29.  ###########         #                   ###             #########      ##     #  
  30.  ############       ###                 #####           ###  #####     ###     ## 
  31.  #####    ####     #####               #######         ###    ###     ####    ### 
  32.  #####    #####   #######             #########       ###      #      ####  #### 
  33.   ####   #####    #######            ###########     ###               ### #### 
  34.    #########      #######           ####     ####    ###               #######   
  35.     ###########    #####           #####     #####    ###     ##      #######  
  36.    #############    ###   ##      ######  #########    ###   ####     ######### 
  37.   ######     ####    #   ####      ########  #####      ##  ######     ###   ### 
  38.  ######     ####     ##########     ####     ####        #########     ###  ##### 
  39.  #####     ####       ##########     ###     ###          #######     ####  ###### 
  40.  #############         ##########     ##     ##            #####      ####   #### 
  41.  ###########            ########      ##     ##             ###        ###    ## 
  42.  
  43.    #######       #     #        #     # 
  44.   ##########    ##     ##      ##     ##             
  45.  ###    ###     ##     ##     ###     ###                                          
  46.   ###    #     ###     ###   #####    ####           Black Sun Research Facility   
  47.     ###         ##     ##    ######   ####             http://blacksun.box.sk      
  48.       ###       ##     ##    #######  ####                 ASCII By : cyRu5        
  49.    #   ###     ###     ###   ####  #######          
  50.   ###  ####   ####     ####   ###   #####                
  51.  ###########   ###########     ##    ### 
  52.   #########      #######        #     # 
  53.  
  54.  
  55. Introduction
  56. ============
  57. This guide is meant for Unix newbies who want to learn a little about basic
  58. Unix security, and how to secure their box.
  59. Most systems come very very insecure out-of-the-box. What is out-of-the-box
  60. (let's call it OOTB from now on), you ask? An OOTB system is a system which
  61. was just installed. All the default configurations are turned on, which means
  62. zero personalization (besides maybe a little personalization made during the
  63. installation process) and quite a lot possible security problems.
  64. Also, there are some very basic concepts that most newbie Unix users aren't
  65. familiar with.
  66.  
  67. During this tutorial, I will teach you how to change default configurations,
  68. basic packet filtering, how to secure your system's networking services (or
  69. completely remove them or some of them, in case you don't need them, in order
  70. to increate your computer's security), how to use, how to avoid trojans, what
  71. are sniffers, how to maintain local security between different users in your
  72. system (if you're not the only one using this system, whether it's locally
  73. or remotely), some stuff about SSH, how to protect yourself against computer
  74. viruses under the Unix system, what are security scanners and how to use
  75. them, why you should encrypt your important data and how etc'.
  76.  
  77. Now, it is advised to go through Black Sun's previous tutorials (see
  78. blacksun.box.sk) prior to reading this tutorial. They contain some basic
  79. concepts and terminology which you need to know and you're might not familiar
  80. with. Also, you should have some basic Unix knowledge and experience. If you
  81. don't have that kind of knowledge yet, we advise you to go to the local
  82. computer store and buy a basic Unix book (it shouldn't cost too much), or,
  83. if you really want to, order a specific one from the Internet (or even
  84. better: go to blacksun.box.sk/books.html and order a book from there. We get
  85. 15% of the money you pay...  :-)  This doesn't mean that you pay more,
  86. though. We simply get 15% out of the money you pay). Don't worry about online
  87. ordering, it's completely secure as long as you order your books from
  88. Amazon.com (they're considered the most secure E-Store on the planet, and I
  89. order lots of books from there).
  90.  
  91. Oh, one last note: this tutorial is in no way a complete one (Duh! It's a
  92. BASIC tutorial, in case you havn't read the title). I included everything I
  93. could possibly think of (that is notable for a beginners guide in this field,
  94. of course). With time, I will add more chapters, so make sure you have the
  95. latest version by visiting blacksun.box.sk often or subscribing to Black Sun's
  96. mailing list (info on how to subscribe at blacksun.box.sk also).
  97.  
  98. Okay, heads up! Here we go!
  99.  
  100. Setting The Ground
  101. ==================
  102. First of all, I assume that you are using either RedHat Linux or Mandrake
  103. Linux. Why is that? Because most Unix newbies use either of these two
  104. distributions. Don't worry, it's no crime to use them or something, and it's
  105. not "lame". Each distribution has it's advantages. RedHat and Mandrake, for
  106. example, both have simple installation and come with a lot of utilities
  107. built-in. That's okay, although I like Slackware Linux and OpenBSD better
  108. (I'll explain why in a second).
  109.  
  110. Now, some of you might be asking right now "but... but I have a different
  111. distribution! Will this stuff work for me too?". Before I answer this
  112. question (to the impatient ones of you, I can already say "yes", but that's
  113. not the exact answer. Read on and you'll understand), I want to explain what
  114. is a distribution (otherwise known as a "distro" or a "flavor" of Unix), why
  115. there are so many of them, where you could learn about all the different
  116. distributions and how to choose the right distribution for you.
  117.  
  118. Unix was first distributed freely and in open-source form. If you're not
  119. familiar with any programming language, then you're not familiar with the
  120. term "source code". I'll explain.
  121.  
  122. The simplest way to show you what source code is is to send you to a
  123. webpage. Take hackernews.com (a personal favorite) for example. Every common
  124. browser has an option to view the page's source from within the browser, but
  125. let's pretend you don't know how to do this or you don't even have this
  126. option within your browser. First, wait for the whole page to load. Then,
  127. save it to your hard drive, a diskette or whatever. Then, open the HTML page
  128. you've just saved with any text editor (Pico, KEdit, Emacs, Notepad,
  129. UltraEdit, whatever).
  130.  
  131. Now what do you see? No more text and graphics and colors and layout, but
  132. plain good instructions. These are HTML instructions. HTML stands for Hyper
  133. Text Marquee Language, and it is the language used to create HTML pages,
  134. which can be read by your browser and used as instructions for how to build
  135. and display the web page.
  136.  
  137.  
  138. The same goes with programming. To create a program, you need to know some
  139. sort fo a programming language (C, for example), and then construct the
  140. program using commands which will later be given to a compiler (which will
  141. turn the source code file into an executable binary file, or in other words, a
  142. program which you can run and play around with) or an interpreter (the program
  143. runs as source code, and gets executed by a program called an interpreter,
  144. which reads the instructions in the source code and performs them. A popular
  145. interpreted programming language is Perl. Interpreted programming languages
  146. usually run slower, but have their advantages. We won't go into that now,
  147. though).
  148.  
  149. Okay, moving on. So now you know what source code is. As I've already
  150. explained, Unix was initially distributed freely and in source code form. This
  151. means that ANYONE with the right knowledge and skills can create his own
  152. version of Unix, to meet his special needs. A different version of Unix is
  153. called a distribution, a "distro" or a "flavor".
  154.  
  155. Now go to www.linuxberg.com. Pick the closest mirror site and then enter the
  156. distributions page. It will display a list of Unix distributions, each one
  157. with it's own characteristics, advantages and disadvantages. This is all nice,
  158. but what happens if people start creating versions of Unix without paying
  159. attention to compatibility issues? For example, if I would have created my own
  160. version of Unix and called ls (the command that lists all files in the current
  161. directory in console mode (text-based interface) or in a virtual console (a
  162. console within a graphical window)) "list" instead? This means that if someone
  163. would have made a program that called the ls command for some purpose, it
  164. wouldn't work anymore (unless I create a command called ls that calls my own
  165. command - list. But in that case, I have to make sure that list has similar
  166. rules to ls). See the problem?
  167.  
  168. Also, if I go to my friend's house, which could be using a different
  169. distribution, how could I possibly use his computer if everything is
  170. completely different?
  171.  
  172. This is why there are standards. Every Unix distribution has to meet these
  173. standards so it will be compatible with other versions. This is also why most
  174. (if not all) of the stuff I am about to teach here will work in all
  175. distributions. If you have a certain problem or question, ask in our message
  176. board (find it at blacksun.box.sk).
  177.  
  178. Oh, almost forgot... in the beginning of this section, I have clearly stated
  179. that I like Slackware Linux and OpenBSD more than RedHat Linux and Mandrake
  180. Linux. Why is that? Simply because they have some advantages, such as even
  181. mroe stability, security, speed and encryption, and they top all the other
  182. distributions in these fields. Of course, they are much harder to work with
  183. (have you ever tried to install OpenBSD?! To a person who installed Mandrake
  184. Linux, which is the easiest to install, and is almost as easy as installing
  185. Windows 95, it would look like hell!!).
  186.  
  187. Okay, let's move on to the actual security information, shall we?
  188.  
  189. First Thing's First: Local Security
  190. ===================================
  191. First of all, let's think: why would you want to improve your computer's local
  192. security? Well, if you're the only one using this computer, and you don't
  193. intend to let anyone into your computer (at least not intentionally), then you
  194. should only read this chapter for pure knowledge. But if you're running a
  195. multi-users system, you definetly should improve your local security.
  196.  
  197. What is local security? Well, better local security means that different users
  198. on this computer, whether they are local users (they have local access to the
  199. computer. They use a keyboard, a monitor and what-not that are
  200. directly connected to the actual box, not through some sort of a local
  201. area network (LAN) or the Internet) or remote users (users accessing your
  202. computer, whether legally or not, using Telnet, SSH, RLogin etc' and through a
  203. local network or the Internet), you need to increate your computer's local
  204. security.
  205.  
  206. Let's start with a basic lesson about file permissions.
  207.  
  208. Unix File Permissions And The Password File
  209. -------------------------------------------
  210. First of all, you need to learn about the way the system works with different
  211. users. Here is a mini-tutorial out of the Byte Me page at my website that will
  212. explain what and how the Unix password file works, thus explain to you a
  213. little more about this subject.
  214.  
  215. Password files == world readable + how do password files look like? 
  216. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  217. First of all, a file that is world readable is a file that can be read by
  218. ANYONE on the system, even the most inferior user. On most systems today, the
  219. password file (usually /etc/passwd) is world readable. Does this mean ANYONE
  220. can get the encrypted passwords and decrypt them? Definetly not!
  221. A password file consists of several (or one) lines, when each line represents
  222. a user.
  223.  
  224. The password file looks like this:
  225. username:password:uid:gid:free text:home directory:shell
  226. Username - the user's username.
  227. Password - the user's password, encrypted using altered DES encryption (can
  228. be cracked in a matter of time, though [note: we'll get to cracking the
  229. password file later]).
  230. UID - User ID. If your UID is 0, you have root priviledges (nothing can stop
  231. you, and you can even type "su username" (without the quotes) to become a
  232. different user. Type exit to return to your root shell after you're done. Btw
  233. SU stands for Switch User). If two users have the same UID, they'll have
  234. identical permissions.
  235. GID - Group ID. The same as UID, with root being GID=0. GID let's you set
  236. ownership patterns and access patterns for a group of users (or a single user)
  237. who have different or identical UIDs but have the same GID. 
  238. Free text - some free text about the user. For info on how to exploit this
  239. field in order to get private information about people, read the Info
  240. Gathering tutorial here.
  241. Home directory - where the user's private configurations files are stored.
  242. Usually /root if you are root, or /usr/your-username or /home/your-username if
  243. you're another user.
  244. Shell - the program that gets executed once you log in. Usually a command
  245. interpreter (a program that receives commands from you and executes them). 
  246.  
  247. Now, most systems will make /etc/passwd world-readable, but don't put the
  248. passwords in it. Instead, they will put a single character, such as *. The
  249. passwords will be stored at the shadow file, which is not world-readable, and
  250. is usually stored at /etc/shadow.
  251. The shadow file is identical to the /etc/passwd file, only it has the
  252. encrypted passwords. Some shadowing programs can also improve the encryption
  253. schemes, but that's not important to us right now.
  254.  
  255. The /etc/passwd has to be world readable if you want to:
  256. 1) Find out what's the username of a certain UID. Very useful in some
  257. situations. For example: each file has an owner. The owner can change access
  258. patterns for this file, or change it's ownership. Root can own all files if
  259. he/she wants to. The owner's UID is inserted into the file. Programs such as
  260. ls (ls stands for list. It views the contents of a directory. For more info
  261. about it and it's uses, type "man ls" without the quotes on a Unix system) can
  262. tell you who owns a file. If they don't have access to the password file
  263. (programs run with your priviledges, unless they are SUID, in which case they
  264. run with the priviledges of the user who SUIDed them. People try not to use
  265. SUID, because it poses lots of security threats), they will only be able to
  266. present you with the UID of the owner. But if they have access to the password
  267. file, they can find the appropriate username for this UID.
  268. 2) Find out information about people (what's their home directory, what's
  269. their shell, what's written in their free text area etc').
  270. 3) Etc' etc' etc'... be creative!
  271.  
  272.               EOF
  273.  
  274. In case you're wondering, EOF stands for End Of File. This means that... well,
  275. duh! End of file! That's it, you've just finished that nice little
  276. mini-tutorial. Now I assume you want to learn how to change file permissions.
  277.  
  278. So, in order to change file permissions, you need to learn how to use the
  279. chmod command. Now, I am about to guide you on the process of finding
  280. information about Unix commands by yourself. It's quite easy.
  281.  
  282. Okay, let's try man first. Man stands for manual. Man is a command that
  283. displays a manual page for a specified command. The syntax is: max command.
  284. For example: man ls, man cd, man more etc'. So let's try to type man chmod.
  285. AHA! No man entry for chmod...   :-/   (some systems might have a man page for
  286. chmod)
  287.  
  288. Let's try using info. We type info chmod. AHA! This time, we're getting
  289. something. So let's see... it says a little about the chmod command, but it
  290. doesn't explain how to use it! Oh, wait, look at this - there are links within
  291. this guide. Simply position your cursor within a word, a couple of words or a
  292. sentence that link somewhere else (they always have a * in front of them) and
  293. hit enter. Keep following links until you learn about chmod and about file
  294. permissions.
  295.  
  296. Runlevels
  297. ---------
  298. I have decided to quote a nice mini-tutorial from the Byte Me page at my
  299. website instead of just writing about runlevels all over again (I don't like
  300. doing things twice).
  301.  
  302. What Are Unix Runlevels?
  303. ++++++++++++++++++++++++
  304. If you've been paying attention to what your Unix box does during startup, you
  305. should have noticed that it says: "Entering runlevel x" (where x is a number
  306. between 1 and 5) at one point of the bootup stage (after it mounts your root
  307. filesystem (your "/" directory) into read-write mode, sets up sound, finds
  308. your RPMs ("Finding module dependencies...") etc'). A runlevel is a
  309. bootup/shutdown sequence. It consists of a list of commands to run on startup
  310. and a list of commands to run on shutdown (or when switching to different
  311. runlevels).
  312.  
  313. Now, first of all, let's see how you can switch runlevels. Bah, that's easy.
  314. Simply type init x, where x is a number between 0 and 6. Runlevel 0 is for
  315. "halt" (turning off your computer, if you have APM -Advanced Power Management,
  316. and if you have APMD - APM Daemon, installed. All modern CPUs have APM),
  317. runlevel 6 is for reboot and the rest are various runlevels. 5 will bootup
  318. everything - it will even automatically run X and ask you for your login
  319. and password in a graphical interface (by default, of course. You can change
  320. this). Runlevel 1 is considered the single-mode runlevel. It does the least
  321. possible (kinda like "safe mode" in Windows) and doesn't even require you to
  322. enter a password (but only root can switch runlevels, so you have to be either
  323. root or have physical access to the computer during startup (we'll get to that
  324. later)).
  325.  
  326. To edit your runlevel list, you can either:
  327. a) Go to /etc/rc.d/rcx.d/ (where x is the runlevel's number) and play around
  328. within this directory. It contains symbolic links (kinda like shortcuts in
  329. Windows. For more information about symbolic links (otherwise known as
  330. "symlinks"), type man ln) to programs (including their parameters) that will
  331. be executed, and symbolic links to programs that will be killed on shutdown.
  332. Play around to find out more (but ALWAYS make backups!!).
  333. b) (this should work on most Unix boxes) Switch to the runlevel you want to
  334. edit. Then type setup. Go to system services, and select/unselect the
  335. services u want to run on startup and kill on shutdown).
  336. c) The easiest way - on most systems, you will be able to type the command
  337. control-panel within an xterm (a "virtual terminal" - a console window within
  338. X-Windows) and get a nice little window thingi with lots of buttons and
  339. suchlikes. Find the button that says "runlevel editor" when you put the mouse
  340. above it for a second or two. Then click on this button and play around with
  341. the programs. I'm sure you'll figure out how to use it yourself. It's quite
  342. self-explanitory, and it contains help files and documentation if you really
  343. need help. 
  344.  
  345. And now, for a nice little runlevels-related hack. 
  346. Now, if you're reading this document, you're probably a Unix newbie, so you
  347. probably use Redhat Linux, Mandrake Linux etc'. If so, you should have a
  348. prompt saying "boot:" or "LILO boot:" or "LILO:" when you start your computer,
  349. and you could either type Windows or Linux (you can change these names into,
  350. say, sucky-OS for Windows and Stable_and_secure_OS for Linux, or anything else
  351. you want. Use the linuxconf program to edit LILO's preferences, and use your
  352. imagination...  :-) ). Now, what happens if you type linux 5? Of course! It
  353. boots up Linux in runlevel 5!! But wait! What happens if you type linux 1 or
  354. linux single? It runs on runlevel 1 - single user mode, which means...
  355. automatic root access! No password needed.   :-)  Most people simply don't
  356. realize how dangerous this could be.
  357.  
  358.               EOF
  359.  
  360. Now, imagine that some evil cracker (e.g. your grandma...  :-) ) reads this
  361. document and then locally roots your computer somehow (the verb 'to root'
  362. means 'to get root access to a computer, not necessarily one that runs Unix').
  363. Scary, huh? That was as easy as stealing a candy from a baby (not that I've
  364. ever done that... /me looks away...   :-) ).
  365.  
  366. Cracking The Password File
  367. --------------------------
  368. As you should already know by now, the password file has some encrypted text
  369. within it. Let's discuss about the encryption scheme first, shall we?
  370.  
  371. Unix password file encryption is based on an altered version of DES
  372. encryption. If you will try to decode an encrypted Unix password (let's call
  373. it a hash from now on. That's the proper name for it) using standard DES
  374. decoding, you will get a null string. Nothing. Nada. Zero. No, not even zero.
  375. You simply won't get anything.
  376.  
  377. So how do you open this door? With a key.  :-)
  378. Key-based encryption (e.g. PGP, which stands for Pretty Good Privacy, and has
  379. very powerful encryption schemes) is an encryption scheme where you need to
  380. have a key, which is a set of letters (lowercase or uppercase), numbers,
  381. symbols etc' (it could be just numbers, symbols and lowercase letters, all
  382. letters, etc').
  383.  
  384. So in Unix "crypt" (from now on, crypt means Unix password file encryption),
  385. the key is actually the first eight characters of the user's password (you can
  386. add extra characters to the key, which can be generated randomly, for extra
  387. security. These are called salts. I won't explain much about them here because
  388. I don't believe I know enough about them to do so), so you need the user's
  389. password to decode the hash (but if you have the user's password, why would
  390. you want to decode his hash if you already have the password?  :-) ).
  391.  
  392. So, crypted passwords cannot be cracked, right? WRONG! You can use a password
  393. cracker such as John the Ripper or Cracker Jack (there are both Unix versions
  394. and Windows versions. Sorry, I don't have URLs to download them) to crack the
  395. hashes. But how do these things work?
  396.  
  397. A password cracker generates random passwords and then tries to break the hash
  398. by using this password as the key. If it fails, it simply tries another
  399. password until it gets it right. Password crackers can try thousands of
  400. passwords per second on modern computers.
  401.  
  402. there are two methods of password cracking - brute-force and dictionary
  403. attacks. In brute-force mode, your password cracker guesses passwords
  404. systematically. You can set a minimum amount of characters for the password,
  405. and tell your cracker what to create the password out of (lowercase letters,
  406. uppercase letters, numbers, symbols etc'). In dictionary attacks, your
  407. password cracker takes words out of a simple text file called a 'dictionary
  408. file'. Each line in this file represents a single word for the password
  409. cracker to try.
  410.  
  411. Dictionary files usually have an advantage over brute-force attacks, because
  412. if you know that the target's password has something to do with dogs, you
  413. could download a dictionary file about dogs. If you know it's the name of some
  414. philosopher, you could download a dictionary file containing the names of all
  415. known philosophers. You can also download all-purpose dictionaries that
  416. contain various words (these usually have the greatest chance to succeed).
  417. The best place to download wordlists from is theargon.com.
  418.  
  419. So, as you can see, if someone obtains your hashes somehow, he could decode
  420. them and break into your computer. This is why all users on your system should
  421. have a long password, and preferably not a dictionary word.
  422.  
  423. If you need help with using a password cracker or have any further questions,
  424. try asking them on the message board at blacksun.box.sk (it's ours, btw... 
  425. :-) ).
  426.  
  427. Trojans
  428. =======
  429. Yes, trojans. Most people who read this might be thinking about Netbus, Back
  430. Orifice, Sub7 and other Windows trojans. These aren't trojans. Okay, I mean,
  431. they ARE trojans, but not this kind of trojans. They are 'remote
  432. administration trojans'. First, let's understand what this name means, and
  433. then you'll see what they have to do with Unix in general and with local
  434. security in particular (as well as remote security). Let's start with the word
  435. trojan:
  436.  
  437. Trpjan - In the Greek mithology, There is a story about the 'trojan horse'. The
  438. Greek were trying to capture the city of Troy for a reason which is beyond this
  439. guide (you should really read the whole story or get the movie or something.
  440. It is quite good). They were camping on the outsides of Troy for about ten
  441. years and they still didn't manage to get in. Then, they came up with a
  442. brilliant plan: the whole army pretended to be leaving the area, and they left
  443. a giant wooden horse for the Trojans as some kind of a present (to honor the
  444. Trojans for being so good). Within this horse sat a couple of soldiers. When
  445. the Trojans found the giant horse, they carried it inside and then, under the
  446. cover of night, the soldiers inside it came out, opened the city's gates and
  447. let the entire Greek army get in, which eventually lead to the fall of the
  448. city of Troy.
  449.  
  450. So, as you see, a trojan program is a program that does not do what it
  451. proclaims to be doing. It could either be a harmless joke (a joke program that
  452. pretends to delete your entire hard drive or any other kinds of computer joke
  453. programs) or a malicious program which could harm your system.
  454.  
  455. Remote administration - To remotely administer a system means to be able to
  456. work on this system as if you had local ("physical") access to it. Being able
  457. to remotely access your system (or "to remotely login to it") is useful for
  458. getting files off your system, working on your system from a distant place
  459. etc'.
  460.  
  461. Remote administration trojan - A trojan program that let's the author of the
  462. program, the person who sent you the program or any other person in the world
  463. access your computer and remotely administer it (this is why Remote
  464. Administration Trojans, or RATs, are often called remote administration
  465. "backdoors" - they open a "back door" for the attacker to get in). This is
  466. exactly like depositing your entire system and evertyhing on it to the hands of
  467. the attacker.
  468.  
  469. The most dangerous thing about RATs would probably be that most of them
  470. (especially Netbus and Sub7) are extremely easy to use and understand, and
  471. come with one or two pages of instructions (yes, they're THAT simple), so any
  472. little kid can use them. Most of these "kids" have no idea what this program
  473. or other programs that do most of the work for them do, which lead to the
  474. nickname "script kiddies" - "lamers" (a lamer is a person who acts immaturely
  475. or stupidly) with programs that do all of the work for them. Technically, a
  476. script kiddie can crack into the Pentagon if he is given a program that does
  477. everything for him. But does he know how this whole thing works? Will he know
  478. what to do once he's in? I doubt it.
  479.  
  480. Now, malicious trojan programs can do a lot more than that. There are also
  481. trojans that allow the attacker to have local access to any user who runs the
  482. program (if root runs it, the whole system is doomed. This is one of the
  483. reasons why no sensible system administrator would work as root all the time,
  484. and instead make himself a less-priviledged account to work with). This is
  485. useful if the attacker has an account on this system and wants to get access
  486. to some other user's files (or even root access, which means access to
  487. practically everything).
  488.  
  489. Also, if you gain write access to a commonly-used application (such as su,
  490. which let's you run a sub-shell as another user by simply giving his password
  491. instead of having to relogin. SU stands for Switch User. Oh, by the way, root
  492. doesn't need to supply a password to su if he wants to gain access to some
  493. other person's account), you can trojan these applications. Let's take su for
  494. example - if you manage to change su so it'll send you every username and
  495. password which it received, you could eventually capture your target's
  496. password or even root's password.
  497.  
  498. So, kids, this is why you should beware of trojans. Be very careful with what
  499. you run. Also, there are programs called checksum checkers. These programs
  500. perform periodical tests (once a day, once an hour, once a week etc, depending
  501. on how you configure them) that determine if the size of some applications
  502. (you can descelect default applications to test or add new applications by
  503. yourself) has changed. If someone has trojaned one of those applications, it's
  504. size should change, but it is also possible (although much harder) to trojan a
  505. program without affecting it's size, but that's out of the topic of this guide.
  506.  
  507. Unix Viruses
  508. ------------
  509. The computer virus problem is much less harsh under the Unix platform, but if
  510. you want to keep your data intact, you should be aware of the problem, which
  511. still exists.
  512.  
  513. There is an incredibly small number of viruses in the wild for the Unix
  514. operating system (a virus that is "in the wild" is a virus that has gone
  515. through a network of any kind and started infecting computers on this network,
  516. just like a biological virus, when it escapes a restricted laboratory
  517. environment and goes into "the wild" and starts infecting people). This is
  518. because virus writers are less motivated to write viruses for Unix, because of
  519. the following reasons:
  520.  
  521. A) Most people who use Unix are more mature than other computer users. Virus
  522. creators who intend to infect other computers are immature people.
  523.  
  524. B) Because of access restrictions in the Unix operating system, if a user runs
  525. a file that is infected with a virus, the virus can't go far, and it can only
  526. do what this user has priviledges to do (although, if a root-priviledged user
  527. runs a virus, it can infect the whole system and freely travel to other
  528. systems). So, because there are files that some users can access and some
  529. other users can't, Unix viruses can't spread far.
  530.  
  531. Still, the problem exists, and we want to protect our data, right? This is why
  532. you should still get yourself a Unix virus scanner. Because of the extreme
  533. lack of viruses in the Unix system, there are no "big titles" of virus
  534. scanners. Try going to altavista.com and searching for Unix virus scanners.
  535. Download some different ones and compare the quality of their scans and the
  536. amount of resources they consume.
  537.  
  538. Encryption
  539. ----------
  540. Encrypt your important files. Use PGP for better encryption.
  541.  
  542. If someone penetrates your computer's security, it will be much much harder
  543. for him to get your important data if you encrypt it.
  544.  
  545. For more information about encryption, read Black Sun's encryption tutorials
  546. at blacksun.box.sk (go to the tutorials page and then find the encryption
  547. section. We have some guides for beginners about PGP and encryption in
  548. general).
  549.  
  550. Remote Security
  551. ===============
  552. Why would you want to improve your computer's remote security? DUH! If you
  553. ever plan to hook your computer into a LAN, the Internet or any other kind of
  554. network, you immediately increase the chance of you getting hacked. You should
  555. definetly attend to your remote security (unless you like getting your ass
  556. rooted).
  557.  
  558. Also, you should read the local security part first, since it contains a lot
  559. of information you need to know before you read this, and also quite a few
  560. tricks that work for both local security and remote security.
  561.  
  562. Remote Root Logins
  563. ------------------
  564. Before I explain to you what is the issue with remote root logins and how to
  565. block them, I need to explain to you what a TTY is first.
  566.  
  567. Unix is a multi-users system, right? And on multi-users systems, many users,
  568. each one with his own monitor or any other type of terminal, can work on the
  569. same computer, right?
  570.  
  571. Now, this computer is obviously running more than one process (a process is a
  572. running program), since it has multiple users on it. Each process receives
  573. some input and sends out some output. Well, then, how will this computer know
  574. which input is whom's and where to direct the output of each program? You
  575. wouldn't want to receive the output of processes that other users are running,
  576. right? (well, technically, if you're a malicious cracker, you'd love to
  577. receive the output of other users' processes, but we're getting off-topic now).
  578.  
  579. This is why each user has a TTY. TTY stands for Terminal TYpe. Each user has
  580. it's own TTY, which can be composed of letters and numbers. That way, the
  581. computer knows where the input comes from (from which TTY) and where to direct
  582. the output to.
  583.  
  584. Okay, first, let's make an experiment. Run a text-based console of an XTerm
  585. window (a console window from within X-Windows, the popular Graphical User
  586. Interface, or GUI, of Unix systems) and type the command who. This will show
  587. who is logged into the system (his username), when he logged in and what is
  588. his TTY. By the way, if you prefer a graphical version of the who command, try
  589. typing gw within an XTerm or within a "run command" box in X. This program
  590. should come with the gnome window manager.
  591.  
  592. Okay, let's move on. Now, that we know what TTYs are, let's edit the file
  593. /etc/securetty with a simple text editor. Now, what do we have here? We have a
  594. list of all TTYs that can log in as a root-priviledged user. My /etc/securetty
  595. file looks like this:
  596.  
  597. tty1
  598. tty2
  599. tty3
  600. tty4
  601. tty5
  602. tty6
  603. tty7
  604. tty8
  605.  
  606. Okay, let me explain myself. Your computer should have eight virtual consoles.
  607. You can switch virtual consoles by pressing ctrl+alt+F1 for console #1,
  608. ctrl+alt+F2 for console #2 etc'. You can imagine how useful this could be.
  609.  
  610. Consoles #7 and #8 are usually reserved for graphical displays, so if you run
  611. X, it should appear in #7, and if you run another X process, it should appear
  612. in #8.
  613.  
  614. These eight local consoles have these TTYs: tty1 for #1, tty2 for #2 etc'.
  615. Now, as you can see, my /etc/securetty file contains only those local TTYs, so
  616. no remote user can login as a root-priviledged user into my computer, even if
  617. he has all the usernames and the passwords.
  618.  
  619. Now, of course, if someone has all the passwords, he could log in as another
  620. user and then use su to switch to root. So the /etc/securetty thing isn't
  621. exactly some fail-proof method, but it'll block off some intruders.
  622.  
  623. Watching Your Processes
  624. -----------------------
  625. If you intend to have several users logged into your system, you should really
  626. watch for what they're running, and how much system resources they're hogging.
  627.  
  628. Here are a few methods to watch your users:
  629.  
  630. Using PS
  631. ++++++++
  632. Type in the command ps -aux. Quite a list, huh? Now, if you want it to be more
  633. readable, try doing ps -aux | more or directing it's output into a file, like
  634. this: ps -aux > some-file-name. If you want to look for specific entries
  635. within this list, try doing ps -aux | grep some-text and it'll display lines
  636. within the output of ps -aux that contain some-text (or whatever you type in).
  637.  
  638. Oh, by the way, as far as I know, PS stands for ProcesseS.
  639.  
  640. Using Top
  641. +++++++++
  642. Type the command top. Cool program, huh? Quite useful... you should have a
  643. whole virtual console or a whole XTerm devoted exclusively for it.
  644.  
  645. If you prefer a graphical display, try typing gtop (a graphical version of top
  646. that comes with the gnome window manager) or kpm (stands for KDE Process
  647. Manager. Comes with the KDE window manager).
  648.  
  649. Eavasdropping
  650. +++++++++++++
  651. If you're a root-priviledged user and you want to see what the other users on
  652. your system are typing, consider using a command called TTY Watch. It will
  653. eavasdrop on the TTY of the user(s) you choose to eavasdrop on, and let you
  654. know exactly what they're typing and exactly what they see on their monitors.
  655.  
  656. Try searching for the latest version of ttywatch at Packet Storm Security
  657. (packetstorm.securify.com), Security Focus (securityfocus.com), Linux.Box
  658. (linux.box.sk), Astalavista (astalavista.box.sk) etc'.
  659.  
  660. Playing With INetD
  661. ------------------
  662. First of all, you need to learn what network daemons are and what INetD is.
  663.  
  664. A daemon is a program similar to TSR programs on Microsoft platforms. TSR
  665. stands for Terminate and Stay Resident. TSRs locate themselves on your
  666. computer's memory, and then stay silent and watch everything. Once certain
  667. credentials are met, the program awakes and does something. For example: when
  668. your free disk space reaches less than, say, 200MBs, the program alerts you.
  669.  
  670. A daemon is the Unix equivelant of Microsoft's TSRs (well, actually, Unix and
  671. it's daemons were around waaaaaaaaay before Microsoft DOS and later Microsoft
  672. Windows started selling). So what is a network daemon? Well, obviously, it's a
  673. daemon that watches for certain credentials that have something to do with
  674. networks. Here are several examples:
  675.  
  676. Example #1: The telnet daemon. Usually listens for incoming connections on
  677. port 23, and then, once this credential is met, it displays a login screen
  678. to the second party. Once the second party enters the correct combination of a
  679. username and a password, it is given a shell environment, where it can
  680. interact with your computer and run commands on it.
  681.  
  682. Example #2: The FTP daemon. FTP stands for File Transfer Protocol, and makes
  683. it easier for different computers to exchange computer files. More info on my
  684. FTP security for extreme newbies tutorial (blacksun.box.sk/ftp.txt).
  685.  
  686. Example #3: A firewall is also a network daemon. Firewalls are programs that
  687. filter incoming and outgoing network packets. They awake once a network event
  688. occurs, and decide whether to allow or disallow it.
  689.  
  690. Now, let's think. Suppose you have twelve different network daemons on your
  691. system. That would take up too much memory for us, right? Then why not just
  692. have a single daemon to do all the ditry work for us and consume less memory?
  693. This is where INetD comes into the picture.
  694.  
  695. INetD stands for InterNet Daemon. You can configure inetd by editing
  696. /etc/inetd.conf (conf stands for configurations). This file should contain
  697. instructions on how to edit it.
  698.  
  699. Updating Your Network Daemons
  700. -----------------------------
  701. You've just got the latest version of your favorite Unix distribution. It came
  702. with an FTP daemon, which you want to run on your system so you could turn it
  703. into an FTP server. But then, someone discovers a hole within this FTP daemon,
  704. and a new version with a fix for this problem goes out. You don't wanna get
  705. caught with your pants down, running an old and buggy FTP daemon, right? Hell,
  706. you could get cracked by some script kiddie and lose your entire hard drive!
  707. We don't want THAT to happen, now do we?
  708.  
  709. First of all, you need to know when a new hole is discovered. You should watch
  710. packetstorm.securify.com on a daily basic, and also subscribe to the BugTraq
  711. mailing list (securityfocus.com). You should also look for mailing lists
  712. concerning the network daemons (also referred to as network services) you are
  713. using.
  714.  
  715. Then, once there are new versions of the network daemons you use, you should
  716. download the latest version and update the files on your system.
  717.  
  718. Network Sniffers
  719. ----------------
  720. For an excellent paper on network sniffers (what are they, how can they risk
  721. your computer's security and how to fight against them), read this excellent
  722. paper: blacksun.box.sk/sniffer.txt.
  723.  
  724. DO NOT Use Telnetd!
  725. ------------------
  726. DO NOT run the telnet daemon on your system! If you want people to be able to
  727. remotely login to your system and run commands on your system, DO NOT use
  728. telnet for this purpose.
  729.  
  730. Instead, you should use SSH (SSH stands for Secure SHell). SSH encrypts your
  731. sessions, so it'll be harder for intruders to eavasdrop you and/or capture any
  732. passwords you enter.
  733.  
  734. Of course, you have to use a special client for SSH, since SSH is very
  735. different than telnet, because of the following reasons:
  736.  
  737. A) SSH encrypts your sessions. Telnet merely creates plain-text TCP sessions.
  738. B) SSH runs on port 22 by default, while telnet stays on port 23. Although
  739. almost every telnet application in existence allows you to create telnet
  740. sessions with any remote host and port specified, some telnet applications
  741. still use port 23. Anyway, ALL telnet applications have port 23 as their
  742. default, so if you type telnet some-host or telnet some-ip, it'll telnet to
  743. that host/IP and into port 23.
  744.  
  745. Get sshd and ssh clients at packetstorm.securify.com, securityfocus.com,
  746. linux.box.sk, astalavista.box.sk etc'.
  747.  
  748. Basic Packet Filtering
  749. ----------------------
  750. First, find these two files: /etc/hosts.allow and /etc/hosts.deny. These two
  751. files can be used to form a basic packet filtering system. Let's start with
  752. /etc/hosts.deny first.
  753.  
  754. Each line in this file should look like this:
  755. host:service
  756.  
  757. Host - a hostname or an IP. You can also use wildcards. For example: *.aol.com
  758. would stand for every host that has a hostname that ends with aol.com.
  759.  
  760. Service - what network service(s) do you want to allow/deny to this host?
  761. Services are defined by their port number. You can also put ALL instead to
  762. block of EVERY well-known port to this host (a well-known port is any port
  763. between 0 and 1024. These ports are called well-known ports because each one
  764. has a default network service associated with it. For example: port 23 is the
  765. default for telnet, port 21 is the default for FTP, port 25 is the default for
  766. Sendmail, port 110 is the default for POP3 etc').
  767.  
  768. Each line within this file represents a combination of a host and a port(s)
  769. that you don't want this host to be able to access. This is called basic
  770. packet filtering.
  771.  
  772. Now, the /etc/hosts.allow file works exactly like hosts.deny, only it contains
  773. hosts that you want to allow access to. Here are a few examples of why you
  774. would need such a thing:
  775.  
  776. Example #1: You want to block every well-known port to AOL users besides port
  777. 21, so they could access your FTP server. To do this, you put *.aol.com:all in
  778. your hosts.deny file and then *.aol.com:21 in your hosts.allow file. As you
  779. can see, hosts.allow has a higher priority than hosts.deny.
  780.  
  781. Example #2: You want to block off AOL users from your FTP server on port 21,
  782. besides foobar.aol.com, which is actually quite nice and always has something
  783. interesting to contribute to your FTP collection. To do this, you put
  784. *.aol.com:21 in hosts.deny and foobar.aol.com:21 in your hosts.allow file.
  785.  
  786. Advanced Packet Filtering
  787. -------------------------
  788. Yup... firewalls.
  789.  
  790. Firewalls are programs that watch everything that comes in and out of your
  791. network or personal computer, and decide what to allow and what to block. Out
  792. of their nature, firewalls need root-priviledges to run (or admin priviledges
  793. on NT networks).
  794.  
  795. Firewalls usually come with a set of premade rules files. Rules files are
  796. files with rules on what to allow and what to deny. These rules files can
  797. block DoS attacks and relatively popular methods of hacking. Also, most
  798. firewalls come with a 'learning mode' option, which is a way of defining your
  799. rules as you go on (whenever something comes in or out, you are asked to
  800. either allow or deny it, and the firewall adapts itselfs to your preferences).
  801.  
  802. The best firewall for Unix (and possibly the best firewall in the world) is
  803. IP
  804.  Chains. Search for the latest version at packetstorm.securify.com (search
  805. for
  806.  ipchains, not ip-chains or ip chains or anything. Otherwise, you probably
  807. won't find anything), securityfocus.com or linux.box.sk.
  808.  
  809. For help using ipchains (ipchains isn't exactly the most user-friendly
  810. firewall in existence), get some ipchains howtos (a howto is a document on how
  811. to do something or how to use something), which probably come with the
  812. ipchains package anyway, together with the executables, the configurations
  813. files etc'. These howtos should help you a lot. 
  814.  
  815. DoS Attacks
  816. -----------
  817. DoS stands for Denial of Service. DoS attacks deny access to a certain service
  818. for a certain person. DoS attacks can crash your computer, disconnect you,
  819. crash your web server programs, SMTP server programs, POP3 server programs
  820. etc', disallow you access to your Email account (a mailbomb (flooding someone
  821. with enormous amounts of Emails. Usually done with some sort of a program which
  822. automates this progress) is also considered a DoS attack (although somewhat
  823. privitive) because it fills up your mailbox and denies you access to it),
  824. block certain remote services and in general anything you can think of that
  825. will deny you access to something.
  826.  
  827. To protect yourself against DoS attacks, I recommend either:
  828.  
  829. a) Getting a good firewall (see previous section).
  830. b) Subscribing to security mailing lists and checking online databases
  831. frequently to get the latest versions of everything and all the latest patches.
  832.  
  833. Security Scanners
  834. -----------------
  835. Security scanners automatically test the security of a network by attempting
  836. to crack into it in different popular ways. It is advised to run one on your
  837. network or home PC (unless you don't run any services on your system, which
  838. makes your system much less vulnerable, in which case there is no need to be
  839. so paranoid. Just avoid default configurations and read all the rest of the
  840. sections and you're pretty much safe) to test it's security, although
  841. just running one isn't enough to secure oneself (follow the rest of the
  842. instructions in this text and read some other texts and books. This text is in
  843. no way complete (ahem... the name is BASIC Local/Remote Unix Security). Try
  844. some of the stuff at blacksun.box.sk's books page).
  845.  
  846. In the next part, I will review some of the best scanners available at the
  847. time this tutorial was written, although not in much depth and detail, since I
  848. am limited in size and time.
  849.  
  850. The Scanners
  851. ++++++++++++
  852. Remote security scanners test the security of a remote network or computer over
  853. a LAN (Local Area Network), a WAN (Wide Area Network, such as the Internet) or
  854. any other kind of network.
  855.  
  856. SATAN
  857. *****
  858. Author: Dan Farmer and Weitse Venema.
  859. Language written in: C and Perl.
  860. Platform built on: some version of Unix.
  861. Requirements: Unix, Perl 5.001+, C, IP header files and root access on the
  862. system you intend to run Satan from.
  863.  
  864. Satan stands for Security Administrator's Tool for Analyzing Networks). It is
  865. the first security scanner that is actually user-friendly. It is built as a
  866. website, where you can choose attacks using simple forms, pulldown boxes,
  867. radio boxes and check boxes, and it displays all the output in an
  868. easily-readable form, ready for printing.
  869.  
  870. Satan also includes a short and easy-to-understand tutorial on each attack,
  871. which makes it an excellent source for security study for beginners. If you're
  872. interested in network security, it is advised to get Satan and try running it
  873. on your computer and scanning your friends (DO NOT scan systems you are not
  874. allowed to scan! It is illegal!).
  875.  
  876. If you prefer the command-line approach, Satan can also be run using a simple
  877. command-line-based interface.
  878.  
  879. Satan can be obtained from the following URL:
  880. http://www.trouble.org/~zen/satan/satan.html
  881.  
  882. As far as I know, there are no Windows NT and Macintosh versions of Satan, but
  883. I havn't checked for a long time now. I expect that there should be a Windows
  884. NT version soon, if there isn't one already.
  885.  
  886. If you're using any version of Linux, you must make several modifications to
  887. run Satan on your system (the next part has been copied from some website. I
  888. forgot the website's URL, but I'm not going to credit these folks anyway,
  889. since I am sure they have stolen this from some book... forgot the book's
  890. name, though...):
  891. a) The file tcp_scan makes incompatible select() calls. To fix this problem, 
  892.  
  893. Nessus
  894. ******
  895. Author: Renaud Deraison.
  896. Language written in: C.
  897. Platform built on: Linux.
  898. Requirements: Linux (most non-Linux distributions will also run it, though,
  899. since they all can emulate each other's programs), C, X-Windows and GTK
  900. (the version of GTK you will need depends on the version of Nessus you intend
  901. to run).
  902.  
  903. Nessu is another excellent remote security scanner. Has a user-friendly
  904. graphical user interface and relatively fast scans. Get Nessus from the
  905. following URL:
  906. http://www.nessus.org
  907.  
  908. IdentTCPScan
  909. ************
  910. Author: Dave Goldsmith.
  911. Language written in: C.
  912. Platform built on: Unix.
  913. Requirements: Unix, C, IP header files.
  914.  
  915. IdentTCPScan has a very useful ability: what it does is that it portscans it's
  916. target (determines which ports are open on the target host), tells you what
  917. service is probably running on this port and tells you which user is running
  918. it by his UID.
  919.  
  920. This can reveal some interesting holes. For example: if it discovers that some
  921. network or computer is running their web server as UID 0 (remember? UID 0 =
  922. root access), this is a serious security hole! If some malicious attacker
  923. exploits a hole in, say, one of the CGIs on this website, he could access ANY
  924. file on the system, since the web server runs as root, hence is not limited
  925. with access. Web servers should run on users that have limited access (in this
  926. case, the web server should only have access to the files contained in the
  927. website and to it's own files, of course).
  928.  
  929. Unfortunately, I don't have an up-to-date URL. Try searching
  930. packetstorm.securify.com or securityfocus.com.
  931.  
  932.  
  933.  
  934. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  935.  
  936.  
  937.  
  938. That's about all for this time, folks. As I have already stated in the
  939. introduction (actually, the next part was copied and pasted from the
  940. introduction chapter): "I included everything I could possibly think of (that
  941. is notable for a beginners guide in this field, of course). With time, I will
  942. add more chapters, so make sure you have the latest version by visiting
  943. blacksun.box.sk often or subscribing to Black Sun's mailing list (info on how
  944. to subscribe at blacksun.box.sk also)."
  945.  
  946. <--! Begin copyright bullshit !--> 
  947. All copyrights are reserved. You may distribute this tutorial freely, as long 
  948. as you keep our names and Black Sun Research Facility's URL at the top of this 
  949. tutorial. 
  950. I have written this tutorial for you, the readers. But I also wish to remain 
  951. the author of this guide, meaning I do not want people to change a line or two 
  952. and then claim that the whole guide is theirs. If you wish to create an 
  953. altered version of this tutorial, please contact me by Email - 
  954. barakirs@netvision.net.il. 
  955. <--! End copyright bullshit !-->
  956.